;(function(window, $) {
  $('.pwdbtn').on('click', function() {
    var pwdObj = {}
    var bool = true
    $('input[type="text"].pwd').each(function() {
      if ($(this).val() === '') {
        layer.alert('请填写' + $(this).data('label'), {
          skin: 'demo-class',
          closeBtn: 0
        })
        // alert('请填写' + $(this).data('label'))
        bool = false
      }
      var value = $(this).val()
      var key = $(this).attr('name')
      pwdObj[key] = value
    })

    var newpwd = $('input[type="text"].new').val()
    var confirm = $('input[type="text"].confirm').val()
    if (newpwd !== confirm) {
      layer.alert('两次密码不一致！', { skin: 'demo-class', closeBtn: 0 })
      // alert('两次密码不一致！')
      bool = false
    }
    if (bool === false) {
      return
    }
    console.log(pwdObj)
    util.ajax({
      url: '/user/updatePwd',
      type: 'post',
      data: pwdObj,
      success: function(res) {
        console.log(res)
        localStorage.clear()
        window.location.href =
          '/login.html?redirect_uri=' +
          encodeURIComponent(window.location.pathname)
      }
    })
  })
})(window, jQuery)
